/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {boolean}
 */
let frontPointer;

const recursivelyCheck = (currentNode) => {
  if (currentNode !== null) {
    if (!recursivelyCheck(currentNode.next)) {
      return false;
    }
    if (frontPointer.val !== currentNode.val) {
      return false;
    }
    frontPointer = frontPointer.next;
  }
  return true;
};

var isPalindrome = function (head) {
  frontPointer = head;
  return recursivelyCheck(head);
};

currentNode = {
  val: 3,
  next: {
    val: 1,
    next: {
      val: 1,
      next: {
        val: 3,
        next: null,
      },
    },
  },
};


console.log(isPalindrome(currentNode));
